import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:live_music/pages/home/square/page_view/note_square.dart';
import 'package:live_music/pages/home/square/page_view/topic_square.dart';
import 'package:live_music/utils/colors.dart';

class PageViewSquare extends StatefulWidget {
  PageViewSquare({Key key}) : super(key: key);

  @override
  _PageViewSquareState createState() => _PageViewSquareState();
}

class _PageViewSquareState extends State<PageViewSquare>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  TabController _tabController;
  final List<Widget> _tabsContent = [NoteSquare(), TopicSquare()];
  final List<Widget> _tabs = [Text('笔记'), Text('话题')];
  @override
  void initState() {
    super.initState();
    _tabController = TabController(
      initialIndex: 0,
      length: _tabs.length,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    double screenWidth = MediaQuery.of(context).size.width;
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        automaticallyImplyLeading: false,
        centerTitle: true,
        title: Container(
            width: 0.35 * screenWidth,
            child: ExtendedTabBar(
              indicatorSize: TabBarIndicatorSize.label,
              controller: _tabController,
              indicatorColor: ColorRes.tabLine,
              indicatorWeight: 2,
              unselectedLabelStyle: TextStyle(
                  color: Colors.grey[600], // 下划线颜色
                  fontSize: 15,
                  fontWeight: FontWeight.w600),
              labelStyle: TextStyle(
                  color: Colors.white,
                  fontSize: 15,
                  fontWeight: FontWeight.w600), //标签文字大小颜色
              tabs: _tabs,
            )),
      ),
      body: ExtendedTabBarView(
        controller: _tabController,
        children: _tabsContent,
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
